package com.raos.example.thread.task;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 异步任务
 *
 * @author raos
 * @email 991207823@qq.com
 * @date 2022/6/16 09:44
 */
@Component
@Slf4j
public class AsyncTask {

    @Async("otherPoolTaskExecutor")
    @SneakyThrows
    public void task1() {
        long t1 = System.currentTimeMillis();
        Thread.sleep(2000); //
        long t2 = System.currentTimeMillis();
        log.info("task1 cost {} ms", t2 - t1);
    }

    @Async
    @SneakyThrows
    public void task2() {
        long start = System.currentTimeMillis();
        Thread.sleep(3000); //
        long ent = System.currentTimeMillis();
        log.info("task2 cost {} ms", ent - start);
    }

}
